<!--
 * @Author: zhangjingyu
 * @Date: 2021-03-17 14:42:22
 * @LastEditors: qinglong
 * @LastEditTime: 2021-05-14 12:26:30
 * @FilePath: \systemCenter\src\views\ftpManage\pricingTrial\onlineConfiger\onlineConfiger.vue
 * @Description: 联机试算页面
-->
<template>
  <!-- 联机试算页面 -->
  <div>
    <el-row class="container">
      <!-- 操作区域 -->
      <upper-template
        @search="(searchForm.page = 1), searchFunc()"
        @clear="clearSearch"
        importIcon
        exportIcon
        :configIcon="false"
      >
        <!-- 操作按钮区 -->
        <template slot="buttonArea">
          <el-button @click="addFunc()">新增</el-button>
          <el-button @click="editFunc()">编辑</el-button>
          <el-button @click="copyFunc()">复制</el-button>
          <el-button @click="delFunc()">删除</el-button>
          <el-button @click="viewInto()">查看</el-button>
          <el-button @click="trial()">试算</el-button>
          <el-button @click="viewCashFlow('0')">查看现金流</el-button>
        </template>
        <!-- 搜索区 -->
        <template slot="searchArea">
          <el-form
            :model="searchForm"
            ref="searchForm"
            label-width="60px"
            label-position="left"
            size="mini"
          >
            <el-form-item label="账号：">
              <el-input v-model="searchForm.acctNo" style="width:150px"></el-input>
            </el-form-item>
            <el-form-item label="机构：" prop="orgCd">
              <el-cascader
                clearable
                filterable
                :options="orgCdList"
                v-model="searchForm.orgCd"
                placeholder="请选择"
                :props="orgCdPropty"
                :show-all-levels="false"
                style="width:150px"
                ref="orgdimTree"
                 @change="checkDim"
              ></el-cascader>
            </el-form-item>
            <el-form-item label="科目：" prop="sbjtCd">
              <auto-form
                v-model="searchForm.sbjtCd"
                elementType="6"
                dimCode="cpm_dim_subject"
                style="width:150px"
              ></auto-form>
            </el-form-item>
            <el-form-item label="币种：" prop="ccyCd">
              <el-select v-model="searchForm.ccyCd" style="width:150px">
                <el-option
                  v-for="item in currencyList"
                  :key="item.ccyCd"
                  :value="item.currencyCode"
                  :label="item.currencyName"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </template>
        <!-- 显示隐藏区 -->
        <template slot="columnHide">
          <el-checkbox-group v-model="checkList">
            <el-checkbox
              v-for="item in textData"
              :label="item.label"
              :key="item.prop"
            >{{ item.label }}</el-checkbox>
          </el-checkbox-group>
        </template>
      </upper-template>

      <el-table
        :header-cell-style="{ 'white-space': 'nowrap', width: 'auto' }"
        ref="multipleTable"
        :data="tableData"
        @row-click="rowChecked"
      >
        <el-table-column width="55" type="selection"></el-table-column>
        <el-table-column prop="acctNo" label="账号" v-if="columnState[0]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="dataDt" label="数据日期" v-if="columnState[1]" show-overflow-tooltip>
          <template slot-scope="scope">
            <div v-if="scope.row.dataDt">{{ timeFormat(scope.row.dataDt) }}</div>
            <div v-else>-</div>
          </template>
        </el-table-column>
        <el-table-column prop="orgCd" label="机构" v-if="columnState[2]"></el-table-column>
        <el-table-column prop="industryCd" label="行业" v-if="columnState[3]"></el-table-column>
        <el-table-column prop="custNo" label="客户编号" v-if="columnState[4]"></el-table-column>
        <el-table-column prop="prdCd" label="产品" v-if="columnState[5]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="sbjtCd" label="科目" v-if="columnState[6]"></el-table-column>
        <el-table-column prop="sbjtTp" label="业务类型" v-if="columnState[7]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="ccyCd" label="币种" v-if="columnState[8]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="matuFlg" label="有无到期日标识" v-if="columnState[9]" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="curBal"
          label="当前余额"
          v-if="columnState[10]"
          show-overflow-tooltip
          :formatter="row => (row.curBal * 1).toFixed(2)"
        ></el-table-column>
        <el-table-column
          prop="origAmt"
          label="原始余额"
          :formatter="row => (row.origAmt * 1).toFixed(2)"
          v-if="columnState[11]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="lastRpricBal"
          label="上次重定价余额"
          :formatter="row => (row.lastRpricBal * 1).toFixed(2)"
          v-if="columnState[12]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="pmtBal"
          label="支付金额"
          :formatter="row => (row.pmtBal * 1).toFixed(2)"
          v-if="columnState[13]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column prop="startDt" label="起息日" v-if="columnState[14]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="matuDt" label="到期日" v-if="columnState[15]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="term" label="原始期限" v-if="columnState[16]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="odueTerm" label="逾期期限" v-if="columnState[17]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="execRate" label="对客利率" v-if="columnState[18]" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="acruIntstBas"
          label="计息基础代码"
          v-if="columnState[19]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="execRateCd"
          label="利率代码"
          v-if="columnState[20]"
          show-overflow-tooltip
        ></el-table-column>

        <el-table-column prop="fltTpCd" label="浮动类型代码" v-if="columnState[21]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="fltRatio" label="浮动比例" v-if="columnState[22]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="fltMargin" label="浮动利差" v-if="columnState[23]" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="lastExecRateChangeDt"
          label="最新执行利率变更日期"
          v-if="columnState[24]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="intstPmtFreq"
          label="结息频率"
          v-if="columnState[25]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column prop="rateTp" label="利率类型代码" v-if="columnState[26]" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="rpricDtAdjstTp"
          label="重定价类型代码"
          v-if="columnState[27]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="lastRpricDt"
          label="上次重定价日期"
          v-if="columnState[28]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="nextRepricDt"
          label="下次重定价日期"
          v-if="columnState[29]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="repricFreq"
          label="重定价频率"
          v-if="columnState[30]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column prop="pmtTp" label="支付类型代码" v-if="columnState[33]" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="lastPrinPmtDt"
          label="上次支付日"
          v-if="columnState[34]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="nextPrinPmtDt"
          label="下次支付日"
          v-if="columnState[35]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="prinPmtFreq"
          label="支付频率"
          v-if="columnState[36]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="bizRatingCd"
          label="业务评级代码"
          v-if="columnState[37]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="custCateCd"
          label="客户类别代码"
          v-if="columnState[38]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column prop="chnlNm" label="渠道" v-if="columnState[39]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="bizNo" label="业务编号" v-if="columnState[40]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="isOdue" label="逾期标识" v-if="columnState[41]" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="earlyPmtAmt"
          label="提前还款金额"
          v-if="columnState[42]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column prop="issuerCd" label="发行人代码" v-if="columnState[43]" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="rateSensitiveFlg"
          label="利率敏感标识"
          v-if="columnState[44]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="instrumentTpCd"
          label="金融工具类型代码"
          v-if="columnState[45]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="costCtrTpCd"
          label="成本中心分类代码"
          v-if="columnState[46]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="isSbjtOdue"
          label="资产负债逾期标识"
          v-if="columnState[47]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="offshoreFlg"
          label="离岸标识"
          v-if="columnState[48]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column prop="sizeFlg" label="规模标识" v-if="columnState[49]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="isAgmt" label="协定标识" v-if="columnState[50]" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="pmtPlanFlg"
          label="还款计划表标识"
          v-if="columnState[51]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="incrementFlg"
          label="增量标识"
          v-if="columnState[52]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="lastRpricExecRate"
          label="上次重定价执行利率"
          v-if="columnState[53]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="nextmtAmt"
          label="下次支付金额"
          v-if="columnState[54]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="firstPrinPmtDt"
          label="首次还款日"
          v-if="columnState[55]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column prop="billRate" label="票面利率" v-if="columnState[56]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="isVlid" label="数据有效性标识" v-if="columnState[57]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="bizLineCd" label="条线" v-if="columnState[58]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="area" label="区域" v-if="columnState[59]" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="outIntstIncExp"
          label="外部利息收支"
          v-if="columnState[60]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column prop="append1" label="备用字段1" v-if="columnState[61]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="append2" label="备用字段2" v-if="columnState[62]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="append3" label="备用字段3" v-if="columnState[63]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="append4" label="备用字段4" v-if="columnState[64]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="append5" label="备用字段5" v-if="columnState[65]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="append6" label="备用字段6" v-if="columnState[66]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="append7" label="备用字段7" v-if="columnState[67]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="append8" label="备用字段8" v-if="columnState[68]" show-overflow-tooltip></el-table-column>
        <el-table-column prop="append9" label="备用字段9" v-if="columnState[69]" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="append10"
          label="备用字段10"
          v-if="columnState[70]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="append11"
          label="备用字段11"
          v-if="columnState[71]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="append12"
          label="备用字段12"
          v-if="columnState[72]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="append13"
          label="备用字段13"
          v-if="columnState[73]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="append14"
          label="备用字段14"
          v-if="columnState[74]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="append15"
          label="备用字段15"
          v-if="columnState[75]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="append16"
          label="备用字段16"
          v-if="columnState[76]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="append17"
          label="备用字段17"
          v-if="columnState[77]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="append18"
          label="备用字段18"
          v-if="columnState[78]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="append19"
          label="备用字段19"
          v-if="columnState[79]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="append20"
          label="备用字段20"
          v-if="columnState[79]"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column prop="dataSrc" label="数据来源" v-if="columnState[79]" show-overflow-tooltip></el-table-column>
      </el-table>
      <pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="searchForm.page"
        :page-size="searchForm.size"
        @refresh="searchFunc"
        :total="total"
      ></pagination>
    </el-row>

    <el-dialog
      v-dialogDrag
      :title="saveTitles[saveFlg - 1]"
      :visible.sync="addOrEdit"
      width="514px"
    >
      <el-form
        :model="saveForm"
        ref="saveForm"
        :disabled="saveFlg == 3"
        label-width="130px"
        label-position="left"
        :rules="saveFormRules"
        :validate-on-rule-change="false"
      >
        <div v-for="(configClass, index) in testConfigDtoMap" :key="index">
          <span class="formTitle">
            <i class="vertical-bar"></i>
            {{ fieldClassifyMap[index + 1] }}
          </span>
          <el-form-item
            v-for="configItem in configClass"
            :key="configItem.testConfig.elementField"
            :label="configItem.businessEle.elementName + '：'"
            :prop="configItem.businessEle.elementType != '5'?configItem.testConfig.elementField:''"
          >
            <!-- 普通类型 1 2 3 4 6 -->
            <auto-form
              v-if="configItem.testConfig.elementField !='orgCd'"
              v-model="saveForm[configItem.testConfig.elementField]"
              :elementType="configItem.businessEle.elementType"
              :elementField="configItem.testConfig.elementField"
              :dimCode="configItem.businessEle.dimensionCode"
              :disabled="getDisabled(configItem.testConfig.elementField)"
            ></auto-form>
            <el-cascader
             v-else-if="configItem.testConfig.elementField =='orgCd'"
                clearable
                filterable
                :options="orgCdList"
                v-model="saveForm[configItem.testConfig.elementField]"
                placeholder="请选择"
                :props="orgCdPropty"
                :show-all-levels="false"
                ref="orgFormdimTree"
                @change="checkFormDim"
              ></el-cascader>
            
            <!-- 期限类型组合 -->
            <template v-if="configItem.businessEle.elementType == '5'">
              <el-form-item
                :prop="configItem.businessEle.elementField"
                style="display: inline-block;width: 100px;"
                :required="configItem.testConfig.inputFlag == '1'"
              >
                <el-input
                  v-model="saveForm[configItem.businessEle.elementField]"
                  :disabled="getDisabled(configItem.testConfig.elementField)"
                ></el-input>
              </el-form-item>
              <el-form-item
                :prop="configItem.businessEle.elementField + 'Mult'"
                style="display: inline-block;width: 100px;"
              >
                <el-select
                  v-model="
                    saveForm[configItem.businessEle.elementField + 'Mult']
                  "
                  :disabled="getDisabled(configItem.testConfig.elementField+ 'Mult')"
                  style="width:100%"
                >
                  <el-option
                    v-for="item in termList"
                    :key="item.value"
                    :value="item.value"
                    :label="item.label"
                  ></el-option>
                </el-select>
              </el-form-item>
            </template>
          </el-form-item>
        </div>
      </el-form>
      <el-dialog title="支付计划表" v-dialogDrag :visible.sync="isPlanShow" width="800px" append-to-body>
        <plan-window :acctNo="saveForm.acctNo" :isPlanShow="isPlanShow"></plan-window>
        <!-- <div slot="footer"></div> -->
      </el-dialog>

      <div slot="footer" class="dialog-footer">
        <el-button
          :disabled="this.saveForm.pmtTp != 'G'"
          v-if="saveFlg != 3"
          @click="isPlanShow = true"
        >编辑还款计划</el-button>
        <el-button @click="saveFunc" v-if="saveFlg != 3">保 存</el-button>
        <el-button @click="addOrEdit = false" v-if="saveFlg != 3">取 消</el-button>
        <el-button @click="addOrEdit = false" v-if="saveFlg == 3">关 闭</el-button>
      </div>
    </el-dialog>
    <!-- 试算结果查询详情 -->
    <el-dialog title="试算结果查询详情" v-dialogDrag :visible.sync="testResultShow">
      <el-row>
        <el-col :span="12" class="resultForm">
          <div>账号：{{resultForm.accaNo}}</div>
          <div>对客利率：{{resultForm.execRate}}</div>
          <div>基础转移价格：{{resultForm.basFtp}}</div>
          <div>FTP利差：{{resultForm.ftpProfitDiff}}</div>
          <div>当日外部收支：{{resultForm.outIntstIncExp}}</div>
          <div>当日FTP净利润：{{resultForm.ftpRetainedProfits}}</div>
          <div>定价状态：{{$getLabel(resultForm.pricStat,pricingStatusList)}}</div>
          <div v-for="(item,i) in adjNameList" :key="item">{{'调整项'+(i+1)+'：'+item}}</div>
        </el-col>
        <el-col :span="12" class="resultForm">
          <div>当前余额：{{resultForm.curBal}}</div>
          <div>业务类型：{{resultForm.sbjtTp}}</div>
          <div>最终转移价格：{{resultForm.finaFtp}}</div>
          <div>当前转移收支：{{resultForm.transIncExp}}</div>
          <div>默认情景：{{resultForm.defaultScene}}</div>
          <div>结果信息：{{resultForm.resultMsg}}</div>
          <div></div>
          <div
            v-for="j in 20"
            :key="j"
          >{{'调整项'+j+'值：'+Number(resultForm['adjst'+j]?resultForm['adjst'+j]:'0').toFixed(6)}}</div>
        </el-col>
      </el-row>
      <div slot="footer">
        <el-button @click="testResultShow = false">关 闭</el-button>
      </div>
    </el-dialog>
    <!-- 查看现金流 -->
    <el-dialog title="查看现金流" v-dialogDrag :visible.sync="showCashFlow">
      <cash-flow :param="cashFlowParam" :flag="showCashFlow"></cash-flow>
      <div slot="footer">
        <el-button @click="showCashFlow = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { systemManage, publicManage_pub, pricingTrial,userOrgan } from "@/api/index";
import { getDict } from "@/api/getDict";
import autoForm from "@/components/ftp/autoForm.vue";
import moment from "moment";
import planWindow from "./com/planTbaleCom";
import cashFlow from "./com/cashFlow";
import { listToTree } from "@/lib/util"; // list转tree
export default {
  data() {
    return {
      addOrEdit: false, // 新增/编辑/查看弹窗
      isPlanShow: false, // 计划表窗口
      saveFlg: 1, // 1:新增，2：编辑，3查看,
      saveTitles: ["新增联机定价数据", "编辑联机定价数据"],
      testResultShow: false,
      // 币种list
      currencyList: [],
      searchForm: {
        acctNo: "",
        orgCd: "",
        sbjtCd: "",
        ccyCd: "",
        page: 1,
        size: 15
      },
      total: 100,
      saveForm: {
        acctNo: "",
        dataDt: "",
        orgCd: "",
        industryCd: "",
        custNo: "",
        prdCd: "",
        sbjtCd: "",
        sbjtTp: "",
        ccyCd: "",
        matuFlg: "",
        curBal: "",
        origAmt: "",
        lastRpricBal: "",
        pmtBal: "",
        startDt: "",
        matuDt: "",
        term: "",
        termMult: "",
        odueTerm: "",
        odueTermMult: "",
        execRate: "",
        acruIntstBas: "",
        execRateCd: "",
        fltTpCd: "",
        fltRatio: "",
        fltMargin: "",
        lastExecRateChangeDt: "",
        intstPmtFreq: "",
        intstPmtFreqMult: "",
        rateTp: "",
        rpricDtAdjstTp: "",
        lastRpricDt: "",
        nextRepricDt: "",
        repricFreq: "",
        repricFreqMult: "",
        pmtTp: "",
        lastPrinPmtDt: "",
        nextPrinPmtDt: "",
        prinPmtFreq: "",
        prinPmtFreqMult: "",
        bizRatingCd: "",
        custCateCd: "",
        chnlNm: "",
        bizNo: "",
        isOdue: "",
        earlyPmtAmt: "",
        issuerCd: "",
        rateSensitiveFlg: "",
        instrumentTpCd: "",
        costCtrTpCd: "",
        isSbjtOdue: "",
        offshoreFlg: "",
        sizeFlg: "",
        isAgmt: "",
        pmtPlanFlg: "",
        incrementFlg: "",
        lastRpricExecRate: "",
        nextmtAmt: "",
        firstPrinPmtDt: "",
        billRate: "",
        isVlid: "",
        bizLineCd: "",
        area: "",
        outIntstIncExp: "",
        append1: "",
        append2: "",
        append3: "",
        append4: "",
        append5: "",
        append6: "",
        append7: "",
        append8: "",
        append9: "",
        append10: "",
        append11: "",
        append12: "",
        append13: "",
        append14: "",
        append15: "",
        append16: "",
        append17: "",
        append18: "",
        append19: "",
        append20: "",
        dataSrc: ""
      },
      // 校验提示错误信息
      errMessage: "",
      saveFormRules: {},
      checkList: [],
      // 列隐藏
      textData: [
        { label: "账号" },
        { label: "数据日期 " },
        { label: "机构" },
        { label: "行业" },
        { label: "客户编号 " },
        { label: "产品" },
        { label: "科目" },
        { label: "业务类型" },
        { label: "币种" },
        { label: "有无到期日标志" },
        { label: "当前余额" },
        { label: "原始余额" },
        { label: "上次重定价余额" },
        { label: "支付金额" },
        { label: "起息日" },
        { label: "到期日" },
        { label: "原始期限" },
        { label: "逾期期限" },
        { label: "对客利率" },
        { label: "计息基础代码" },
        { label: "利率代码" },
        { label: "浮动类型代码" },
        { label: "浮动比例" },
        { label: "浮动利差" },
        { label: "最新执行利率变更日期" },
        { label: "结息频率" },
        { label: "利率类型代码" },
        { label: "重定价类型代码" },
        { label: "上次重定价日期" },
        { label: "下次重定价日期" },
        { label: "重定价频率" },
        { label: "支付类型代码" },
        { label: "上次支付日" },
        { label: "下次支付日" },
        { label: "支付频率" },
        { label: "业务评级代码" },
        { label: "客户类别代码" },
        { label: "渠道" },
        { label: "业务编号" },
        { label: "逾期标识" },
        { label: "提前还款金额" },
        { label: "发行人代码" },
        { label: "利率敏感标识" },
        { label: "金融工具类型代码" },
        { label: "成本中心分类代码" },
        { label: "资产负债逾期标识" },
        { label: "离岸标识" },
        { label: "规模标识" },
        { label: "协定标识" },
        { label: "还款计划表标识" },
        { label: "增量标识" },
        { label: "上次重定价执行利率" },
        { label: "下次支付金额" },
        { label: "首次还款日" },
        { label: "票面利率" },
        { label: "数据有效性标识" },
        { label: "条线" },
        { label: "区域" },
        { label: "外部利息收支" },
        { label: "备用字段1" },
        { label: "备用字段2" },
        { label: "备用字段3" },
        { label: "备用字段4" },
        { label: "备用字段5" },
        { label: "备用字段6" },
        { label: "备用字段7" },
        { label: "备用字段8" },
        { label: "备用字段9" },
        { label: "备用字段10" },
        { label: "备用字段11" },
        { label: "备用字段12" },
        { label: "备用字段13" },
        { label: "备用字段14" },
        { label: "备用字段15" },
        { label: "备用字段16" },
        { label: "备用字段17" },
        { label: "备用字段18" },
        { label: "备用字段19" },
        { label: "备用字段20" },
        { label: "数据来源" }
      ],
      // 获取table的数据
      tableData: [],
      // 是否显示现金流弹窗
      showCashFlow: false,
      cashFlowParam: {}, // 传入现金流组件的参数
      //编辑行内数据暂存，供判断表单状态
      editRow: {},
      // 表单title分类
      fieldClassifyMap: {
        "1": "基础信息",
        "2": "利率信息",
        "3": "期限信息",
        "4": "支付信息",
        "5": "重定价信息",
        "6": "其他信息",
        "7": "备用字段"
      },
      // toForm表单详情,供遍历
      testConfigDtoMap: [],
      // //期限下拉
      termList: [
        { value: "Y", label: "年" },
        { value: "M", label: "月" },
        { value: "D", label: "日" }
      ],
      // // 业务类型下拉
      sbjtTpList: [],
      // 定价状态下拉
      pricingStatusList: [],
      // // 计息基础下拉
      // acruIntstBasList: [],
      // // 支付类型下拉
      // pmtTpList: [],
      // // 还款计划标识下拉
      // pmtPlanFlgList: [],
      // // 利率类型
      // rateTpList: [],
      // // 重定价类型下拉
      // rpricDtAdjstTpList: [],
      // // 业务评级下拉
      // bizRatingList: [],
      // // 渠道
      // chnlNmList: [],
      // // 逾期标识下拉
      // isOdueList: [],
      // // 资产负债逾期标识下拉
      // isSbjtOdueList: [],
      // // 金融工具类型下拉
      // instrumentTpList: [],
      // // 规模标识
      // sizeFlgList: [],
      // // 增量标识下拉
      // incrementFlgList: [],
      // // 来源系统
      // dataSrcList: [],
      // //客户类别
      // custCateList: [],
      // // 发行人
      // issuerList: [],
      // // 成本中心分类
      // costCtrTpList: [],
      // // 离岸标识
      // offshoreFlgList: [],
      // // 协定标识
      // isAgmtList: [],
      // // 数据有效性标识下拉
      // isVlidList: []
      resultForm: {},
      adjNameList: [
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        "",
        ""
      ],
      orgCdPropty:{
        checkStrictly: true,
        emitPath: false,
        multiple:this.multiple,
        value: "dictItemCode",
        label: "dictItemName"
      },
      //权限机构数据
      orgCdList:[],
    };
  },
  components: {
    "auto-form": autoForm,
    "plan-window": planWindow,
    "cash-flow": cashFlow
  },
  created() {
    this.checkListInit();
    this.searchFunc();
    this.getDict();
    this.getCcyList();
    this.getOrgList();
  },
  computed: {
    columnState() {
      let arr = [],
        arr1 = this.textData,
        arr2 = this.checkList;
      for (let i = 0; i < arr1.length; i++) {
        let flg = false;
        for (let j = 0; j < arr2.length; j++) {
          if (arr1[i].label === arr2[j]) {
            flg = true;
          }
        }
        arr.push(flg);
      }
      return arr;
    }
  },
  mounted() {},
  watch: {
    addOrEdit() {
      // 窗口打开或关闭清除校验结果
      if (this.$refs.saveForm) {
        this.$refs.saveForm.clearValidate();
      }
    },
    "saveForm.rateTp"(n, o) {
      if (n != "A") {
        this.saveForm.rpricDtAdjstTp = "";
        this.saveForm.repricFreq = "";
        this.saveForm.repricFreqMult = "";
        this.saveForm.lastRpricDt = "";
        this.saveForm.nextRepricDt = "";
      }
      if (n == "A") {
        this.saveForm.lastRpricDt = moment(new Date()).format("YYYY-MM-DD");
      }
    },
    "saveForm.pmtTp"(n, o) {
      if (n == "A") {
        this.saveForm.prinPmtFreq = "";
        this.saveForm.prinPmtFreqMult = "";
        this.saveForm.nextPrinPmtDt = "";
      }
    }
  },
  methods: {
    clearSearch() {
      this.searchForm.acctNo = "";
      this.searchForm.orgCd = "";
      this.searchForm.sbjtCd = "";
      this.searchForm.ccyCd = "";
      this.searchForm.page = 1;
    },
    // 获取所有字段的配置
    toForm() {
      let data = {
        acctNo: this.saveForm.acctNo,
        operateType: this.saveFlg
      };
      pricingTrial.onlineToForm(data).then(res => {
        if (res.code == 200) {
          this.fieldClassifyMap = res.data.fieldClassifyMap;
          this.testConfigDtoMap = Object.values(res.data.testConfigDtoMap);
          // 表单查出的字段是翻译过的，这里toform返回了所有原始字段录入的信息，拿这个用来填充saveForm
          let form = { ...res.data.onlinePricingTest };
          for (const key in form) {
            if (typeof form[key] == "number") {
              form[key] += "";
            }
          }
          this.editRow = form;
          for (const key in this.saveForm) {
            this.saveForm[key] = form[key];
          }
          this.rulesUpdate();
          this.addOrEdit = true;
          console.log(this.saveForm);
        }
      });
    },
    // 校验规则更新
    rulesUpdate() {
      let rules = {
        acctNo: [
          {
            pattern: /^[A-Z_0-9]{3,40}$/,
            message: "只能输入3-40位的大写英文字母或数字",
            trigger: "blur"
          }
          // { validator: this.acctNoValid, trigger: "blur" }
        ],
        custNo: [
          {
            pattern: /^[\u4E00-\u9FA5A-Za-z0-9_]{0,20}$/,
            message: "只能输入0-20位英文字母、数字、汉字、下划线",
            trigger: "blur"
          }
        ],
        origAmt: [
          {
            pattern: /(^[0-9]{1,18}$)|(^[0-9]{1,18}[\.]{1}[0-9]{1,4}$)/,
            message: "只能输入整数小于18位，小数小于4位的数字",
            trigger: "blur"
          }
        ],
        curBal: [
          {
            pattern: /(^[0-9]{1,18}$)|(^[0-9]{1,18}[\.]{1}[0-9]{1,4}$)/,
            message: "只能输入整数小于18位，小数小于4位的数字",
            trigger: "blur"
          }
        ],
        pmtBal: [
          {
            pattern: /(^[0-9]{1,18}$)|(^[0-9]{1,18}[\.]{1}[0-9]{1,4}$)/,
            message: "只能输入整数小于18位，小数小于4位的数字",
            trigger: "blur"
          }
        ],
        nextmtAmt: [
          {
            pattern: /(^[0-9]{1,18}$)|(^[0-9]{1,18}[\.]{1}[0-9]{1,4}$)/,
            message: "只能输入整数小于18位，小数小于4位的数字",
            trigger: "blur"
          }
        ],
        earlyPmtAmt: [
          {
            pattern: /(^[0-9]{1,18}$)|(^[0-9]{1,18}[\.]{1}[0-9]{1,4}$)/,
            message: "只能输入整数小于18位，小数小于4位的数字",
            trigger: "blur"
          }
        ],
        lastRpricExecRate: [
          {
            pattern: /(^[0-9]{1,6}$)|(^[0-9]{1,6}[\.]{1}[0-9]{1,6}$)/,
            message: "只能输入整数小于6位，小数小于6位的数字",
            trigger: "blur"
          }
        ],
        execRate: [
          {
            pattern: /(^[0-9]{1,6}$)|(^[0-9]{1,6}[\.]{1}[0-9]{1,6}$)/,
            message: "只能输入整数小于6位，小数小于6位的数字",
            trigger: "blur"
          }
        ],
        fltMargin: [
          {
            pattern: /(^[0-9]{1,6}$)|(^[0-9]{1,6}[\.]{1}[0-9]{1,6}$)/,
            message: "只能输入整数小于6位，小数小于6位的数字",
            trigger: "blur"
          }
        ],
        billRate: [
          {
            pattern: /(^[0-9]{1,6}$)|(^[0-9]{1,6}[\.]{1}[0-9]{1,6}$)/,
            message: "只能输入整数小于6位，小数小于6位的数字",
            trigger: "blur"
          }
        ],
        lastRepricBal: [
          {
            pattern: /(^[0-9]{1,18}$)|(^[0-9]{1,18}[\.]{1}[0-9]{1,4}$)/,
            message: "只能输入整数小于18位，小数小于4位的数字",
            trigger: "blur"
          }
        ],
        outIntstIncExp: [
          {
            pattern: /(^[0-9]{1,18}$)|(^[0-9]{1,18}[\.]{1}[0-9]{1,4}$)/,
            message: "只能输入整数小于18位，小数小于4位的数字",
            trigger: "blur"
          }
        ],
        bizNo: [
          {
            pattern: /^[0-9]{0,9}$/,
            message: "只能输入小于9位正整数",
            trigger: "blur"
          }
        ],
        term: [
          {
            pattern: /^[0-9]{0,9}$/,
            message: "只能输入小于9位正整数",
            trigger: "blur"
          }
        ],
        termMult: [
          {
            validator: (rule, value, callback) => {
              if (this.saveForm.term && value == "") {
                callback(new Error("请填补全单位"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ],
        intstPmtFreq: [
          {
            pattern: /^[0-9]{0,9}$/,
            message: "只能输入小于9位正整数",
            trigger: "blur"
          }
        ],
        intstPmtFreqMult: [
          {
            validator: (rule, value, callback) => {
              if (this.saveForm.intstPmtFreq && value == "") {
                callback(new Error("请填补全单位"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ],
        odueTerm: [
          {
            pattern: /^[0-9]{0,9}$/,
            message: "只能输入小于9位正整数",
            trigger: "blur"
          }
        ],
        odueTermMult: [
          {
            validator: (rule, value, callback) => {
              if (this.saveForm.odueTerm && value == "") {
                callback(new Error("请填补全单位"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ],
        prinPmtFreq: [
          {
            pattern: /^[0-9]{0,9}$/,
            message: "只能输入小于9位正整数",
            trigger: "blur"
          },
          {
            validator: (rule, value, callback) => {
              if (
                this.saveForm.pmtTp &&
                this.saveForm.pmtTp != "A" && this.saveForm.pmtTp != "G" &&
                value == ""
              ) {
                this.errMessage =
                  "支付类型不是一次性还本付息或不是根据还款计划时 <strong>支付频率</strong>不能为空";
                callback(new Error("请填写支付频率"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ],
        prinPmtFreqMult: [
          {
            validator: (rule, value, callback) => {
              if (this.saveForm.prinPmtFreq && value == "") {
                callback(new Error("请填补全单位"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ],
        rpricDtAdjstTp: [
          {
            validator: (rule, value, callback) => {
              if (this.saveForm.rateTp == "A" && value == "") {
                this.errMessage =
                  "利率类型为浮动利率时 <strong>重定价类型</strong>不能为空";
                callback(new Error("利率类型为浮动利率时，重定价类型不能为空"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ],
        repricFreq: [
          {
            pattern: /^[0-9]{0,9}$/,
            message: "只能输入小于9位正整数",
            trigger: "blur"
          },
          {
            validator: (rule, value, callback) => {
              if (this.saveForm.rateTp == "A" && value == "") {
                this.errMessage =
                  "利率类型为浮动利率时 <strong>重定价频率</strong>不能为空";
                callback(new Error("利率类型为浮动利率时，重定价频率不能为空"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ],
        repricFreqMult: [
          {
            validator: (rule, value, callback) => {
              if (this.saveForm.repricFreq && value == "") {
                callback(new Error("请填补全单位"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ],
        pmtTp: [
          {
            validator: (rule, value, callback) => {
              if (this.saveForm.matuFlg == "1" && value == "") {
                this.errMessage = "有到期日时<strong>支付类型</strong>不能为空";
                callback(new Error("请填写支付类型"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ],
        rateTp: [
          {
            validator: (rule, value, callback) => {
              if (this.saveForm.matuFlg == "1" && value == "") {
                this.errMessage = "有到期日时<strong>利率类型</strong>不能为空";
                callback(new Error("请填写利率类型"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ]
      };
      // 找必填的项加入校验规则前
      for (let key in this.testConfigDtoMap) {
        for (
          let index = 0;
          index < this.testConfigDtoMap[key].length;
          index++
        ) {
          const el = this.testConfigDtoMap[key][index];
          if (!rules[el.testConfig.elementField]) {
            rules[el.testConfig.elementField] = [];
          }
          if (el.testConfig.inputFlag == "1") {
            rules[el.testConfig.elementField].unshift({
              required: true,
              message: "请输入必填项",
              trigger: "blur"
            });
          }
        }
      }
      this.saveFormRules = rules;
      this.$forceUpdate();
    },
    // 初始化table显示隐藏状态
    checkListInit() {
      this.checkList = this.textData.map(v => {
        return v.label;
      });
    },
    // 获取机构数据
    getOrgList() {
        debugger;
      userOrgan.queryCurrentUserOrgTree().then(res => {
          debugger
        if(res.code == 200){
            this.orgCdList = listToTree("dictItemCode", "parentItemCode",res.datas);
        }
       
      });
    },
    // 获取可用币种
    getCcyList() {
      publicManage_pub
        .currencyManageQueryAvailable({ page: 1, size: 999 })
        .then(res => {
          this.currencyList = res.data;
        });
    },
    // 获取所有字典
    getDict() {
      //  getDict('').then(res=>{
      //    if(res.code==200){
      //      this.sbjtTpList = res.datas
      //    }
      //  });
      getDict("ftp_pricing_status").then(res => {
        if (res.code == 200) {
          this.pricingStatusList = res.datas;
        }
      });
    },
    // 查询
    searchFunc() {
      let data = this.searchForm;
      pricingTrial.onlineFindAll(data).then(res => {
        if (res.code == 200) {
          this.total = res.total;
          this.tableData = res.rows;
        }
        // this.tableData = res.data.sort((x, y) => {
      });
    },
    addFunc() {
      this.saveFlg = 1;
      for (let k in this.saveForm) {
        this.saveForm[k] = "";
      }
      this.toForm();
    },
    editFunc() {
      this.saveFlg = 2;
      let selection = this.$refs.multipleTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据进行修改");
      }
      let row = selection[0];
      this.saveForm.acctNo = row.acctNo;
      this.toForm();
    },
    copyFunc() {
      this.saveFlg = 5;
      let selection = this.$refs.multipleTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据进行复制");
      }
      let row = selection[0];
      this.saveForm.acctNo = row.acctNo;
      this.toForm();
    },
    // 编号是否重复校验
    acctNoValid(rule, value, callback) {
      // 只在新增时校验
      if (this.saveFlg != 1) {
        callback();
        return;
      }
      pricingTrial
        .onlinePricingTestCheckUsing({ validateParam: "acctNo:" + value })
        .then(res => {
          if (res.success) {
            callback();
          } else {
            callback(new Error("编号已存在"));
          }
        });
    },
    saveFunc() {
      // 清空上次校验错误信息
      this.errMessage = "";
      this.$refs["saveForm"].validate(valid => {
        if (valid) {
          let data = {
            onlinePricingTest: this.saveForm,
            operateType: this.saveFlg
          };
          pricingTrial.onlinePricingTestSave(data).then(res => {
            if (res.code == 200) {
              this.$message.success("保存成功");
              this.addOrEdit = false;
              this.searchFunc();
            } else {
              this.$message.error(res.message || "保存失败");
            }
          });
        } else {
          this.$message.warning({
            dangerouslyUseHTMLString: true,
            message:
              this.errMessage || "您有校验未通过，请检查，根据表单提示填写",
            duration: 4000
          });
        }
      });
    },
    delFunc() {
      let selection = this.$refs.multipleTable.selection;
      if (selection.length < 1) {
        return this.$message.warning("请选择要删除的数据");
      }
      this.$confirm("您确定要删除选中数据吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          let data = { ids: selection.map(v => v.acctNo) };
          pricingTrial.onlinePricingTestRemove(data).then(res => {
            if (res.code == 200) {
              this.$message.success("删除成功");
              this.searchFunc();
            } else {
              this.$message.error(res.message || "删除失败");
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 查看
    viewInto(data) {
      this.saveFlg = 3;
      let selection = this.$refs.multipleTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据查看");
      }
      let row = selection[0];
      this.saveForm.acctNo = row.acctNo;
      this.toForm();
    },
    // 试算
    trial() {
      let selection = this.$refs.multipleTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条要试算的内容");
      }
      this.testResultShow = true;
      let row = selection[0];
      let data = { acctNo: row.acctNo };
      pricingTrial.showTestResult(data).then(
        res => {
          if (res.code == 200) {
            this.resultForm = res.data.testResult || {};
            this.resultForm.ftpProfitDiff = res.data.ftpProfitDiff;
            this.resultForm.defaultScene = res.data.defaultScene;
            this.resultForm.resultMsg = res.data.resultMsg;
            this.resultForm.ftpRetainedProfits = res.data.ftpRetainedProfits;
            this.resultForm.execRate = row.execRate;
            this.resultForm.curBal = row.curBal;
            this.resultForm.sbjtTp = row.sbjtTp;
            this.resultForm.outIntstIncExp = row.outIntstIncExp;
            this.adjNameList = res.data.adjNameList || [];
            this.$message.success(res.message || "成功");
          } else {
            this.$message.error(res.message || "试算查询失败");
          }
        },
        err => {
          console.log(err);
        }
      );
    },
    // 查看现金流
    viewCashFlow() {
      let selection = this.$refs.multipleTable.selection;
      if (selection.length != 1) {
        return this.$message.warning("请选择一条数据");
      }
      let row = selection[0];
      let data = {
        acctNo: row.acctNo
      };
      this.cashFlowParam = data;
      this.showCashFlow = true;
    },
    getDisabled(field) {
      if (field == "acctNo" && this.saveForm.acctNo != "") return true;
      if (
        (field == "rpricDtAdjstTp" ||
          field == "repricFreq" ||
          field == "repricFreqMult" ||
          field == "lastRpricDt" ||
          field == "nextRepricDt") &&
        this.saveForm.rateTp != "A"
      )
        return true;
      if (
        (field == "nextPrinPmtDt" ||
          field == "prinPmtFreq" ||
          field == "prinPmtFreqMult") &&
        this.saveForm.pmtTp == "A"
      )
        return true;

      return false;
    },
    rowChecked(row) {
      if (this.$refs.multipleTable) {
        this.$refs.multipleTable.clearSelection();
        this.$refs.multipleTable.toggleRowSelection(row, true);
      }
    },
    timeFormat(val) {
      if (val) return moment(val).format("YYYY-MM-DD");
      else return "";
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.searchForm.size = val;
      this.searchFunc();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.searchForm.page = val;
      this.searchFunc();
    },
    checkDim() {
      this.$refs.orgdimTree.dropDownVisible = false;
    },
    checkFormDim() {
         this.$refs.orgFormdimTree.dropDownVisible = false;
    }
  }
};
</script>

<style lang="scss" scoped>
.dialogSearchBox {
  header {
    text-align: center;
    span {
      margin: 0 20px;
    }
  }
}
// /deep/.el-table__header-wrapper thead tr th {
//   white-space: nowrap !important;
// }
.formTitle {
  font-size: 14px;
  font-weight: 700;
  display: block;
  margin-bottom: 10px;
}
.resultForm > div {
  height: 16px;
  line-height: 16px;
  vertical-align: middle;
  padding-bottom: 5px;
}
</style>